from typing import List

from infirmary_admin_src.infirmary_common.infirmary_controller import IBaseController
from infirmary_admin_src.infirmary_common.infirmary_controller.rest_controller_with_depends import \
    RestControllerWithDepends
from fastapi import Request, Depends, Path, Body

from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.schemas import SchemaBase
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.employee.services import EmployeeBusinesses




class XParam(SchemaBase):
    '''
    账号密码登录参数
    '''

    employee_id: int = Body(default=1, alias='employeeId', title="employeeId", description='用户ID')
    actual_name: str = Body(None, alias='actualName', title="department_id", description='用户名称')
    administrator_flag: bool = Body(False, alias='administratorFlag', title="administrator_flag",
                                    description='是否禁用标记')
    deleted_flag: bool = Body(False, alias='deletedFlag', title="deleted_flag", description='是否禁用标记')
    department_id: str = Body(None, alias='departmentId', title="departmentId", description='department_id')
    disabled_flag: int = Body(default=1, alias='disabledFlag', title="disabledFlag", description='权限类型')
    gender: int = Body(default=1, alias='gender', title="gender", description='性别')
    login_name: str = Body(None, alias='loginName', title="loginName", description='loginName')
    remark: str = Body(None, alias='remark', title="remark", description='remark')
    phone: str = Body(None, alias='phone', title="phone", description='loginName')
    update_time: str = Body(None, alias='updateTime', title="updateTime", description='loginName')
    roleIdList: List[int] = Body(default=[], alias='roleIdList', title="roleIdList", description='性别')


class IController(IBaseController):
    '''
    定制相关约束检测函数逻辑步序
    '''

    def __init__(self, *, request: Request,
                 schema_param: XParam,
                 ):
        super().__init__(request=request)
        # 入参参数
        # 入参参数
        self.schema_param = schema_param


@RestControllerWithDepends()
class SystemEmployeeUpdateController(IController):

    def business_login(self):
        pass
        # 查询用户信息，联表查询比较麻烦
        #  **{**self.schema_param.dict(exclude_unset=True, exclude={'is_trusted'}),
        result = EmployeeBusinesses.edit_sys_employee_and_role(
            employee_id=self.schema_param.employee_id,
            roleIdList=self.schema_param.roleIdList,
            **self.schema_param.dict(exclude_unset=True, exclude={'employee_id', 'roleIdList'}),
        )
        if result:
            self.response_msg = '更新成功'
        else:
            self.response_ok = False
            self.response_msg = '更新失败'
            return None

        return None
